package com.yhos.platform.oopston.web.api;

import com.yhos.platform.oopston.base.config.OopstonConfig;
import com.yhos.platform.oopston.core.annotation.ChannelType;
import com.yhos.platform.oopston.core.annotation.ParamsValid;
import com.yhos.platform.oopston.core.base.Response;
import com.yhos.platform.oopston.core.base.Result;
import com.yhos.platform.oopston.core.exception.BusinessException;
import com.yhos.platform.oopston.core.utils.MapperUtils;
import com.yhos.platform.oopston.mapper.model.fish.FishTrackResponseApiModel;
import com.yhos.platform.oopston.mapper.model.oopston.*;
import com.yhos.platform.oopston.mapper.model.shunfeng.ShunfengOrderCreateRequestApiModel;
import com.yhos.platform.oopston.mapper.model.shunfeng.ShunfengOrderCreateResponseApiModel;
import com.yhos.platform.oopston.mapper.model.zhongtong.ZhongTongOrderCreateRequestApiModel;
import com.yhos.platform.oopston.service.biz.OrderBiz;
import com.yhos.platform.oopston.service.biz.ShunfengOrderBiz;
import com.yhos.platform.oopston.web.api.dto.fish.FishTrackResponseApiDTO;
import com.yhos.platform.oopston.web.api.dto.oopston.*;
import com.yhos.platform.oopston.web.api.dto.shunfeng.ShunfengOrderCreateRequestApiDTO;
import com.yhos.platform.oopston.web.api.dto.shunfeng.ShunfengOrderCreateResponseApiDTO;
import com.yhos.platform.oopston.web.api.dto.zhongtong.ZhongTongOrderCreateRequestApiDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;
import java.util.UUID;

@Api(value = "订单")
@RestController
@RequestMapping(value = "/api/order")
public class OrderApiController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private OrderBiz orderBiz;

    @Autowired
    private ShunfengOrderBiz shengfengOrderBiz;

    @Autowired
    private OopstonConfig oopstonConfig;


/*    *//**
     * 提交订单
     * @param requestApiDTO
     * @return
     */
    @ApiOperation(value = "提交订单", notes = "提交订单")
    @PostMapping("create")
    @ChannelType(channels = "OST")
    public Response<OrderCreateResponseApiDTO> create(@RequestBody @ParamsValid @ApiParam OrderCreateRequestApiDTO requestApiDTO) {
        OrderCreateResponseApiModel responseApiModel = orderBiz.createOrder(MapperUtils.mapper(requestApiDTO, OrderCreateRequestApiModel.class));
        OrderCreateResponseApiDTO responseApiDTO = MapperUtils.mapper(responseApiModel, OrderCreateResponseApiDTO.class);
        return Result.SUCCESS(responseApiDTO);
    }

    /**
     * 取消订单
     * @param requestApiDTO
     * @return
     */
    @ApiOperation(value = "取消订单", notes = "取消订单")
    @PostMapping("cancel")
    public Response<OrderCancelResponseApiDTO> cancel(@RequestBody @ParamsValid @ApiParam OrderCancelRequestApiDTO requestApiDTO) {
        OrderCancelRequestApiModel requestApiModel = MapperUtils.mapper(requestApiDTO, OrderCancelRequestApiModel.class);
        OrderCancelResponseApiModel responseApiModel = orderBiz.cancelOrder(requestApiModel);
        OrderCancelResponseApiDTO responseApiDTO = MapperUtils.mapper(responseApiModel, OrderCancelResponseApiDTO.class);
        return Result.SUCCESS(responseApiDTO);
    }

    /**
     * 获取订单跟踪信息
     * @param requestApiDTO
     * @return
     */
    @ApiOperation(value = "获取订单跟踪信息", notes = "获取订单跟踪信息")
    @PostMapping("tracking")
    public Response<OrderGetTrackResponseApiDTO>tracking(@RequestBody @ParamsValid @ApiParam OrderGetTrackRequestApiDTO requestApiDTO) {
        OrderGetTrackResponseApiModel responseApiModel = orderBiz.getOrderTrack(Long.valueOf(requestApiDTO.getOrderId()));
        return Result.SUCCESS(MapperUtils.mapper(responseApiModel, OrderGetTrackResponseApiDTO.class));
    }

    /**
     * 获取订单跟踪信息 批量
     * @param requestApiDTO
     * @return
     */
    @ApiOperation(value = "获取订单跟踪信息 批量", notes = "获取订单跟踪信息 批量")
    @PostMapping("trackingBatch")
    public Response<OrderGetTrackResponseBatchApiDTO>trackingBatch(@RequestBody @ParamsValid @ApiParam OrderGetTrackRequestApiDTO requestApiDTO) {
        OrderGetTrackDetailResponseBatchApiModel responseApiModel = orderBiz.getOrderTrackBatchSave();
        return Result.SUCCESS(MapperUtils.mapper(responseApiModel, OrderGetTrackResponseBatchApiDTO.class));
    }

    /**
     * 提交订单
     * @param requestApiDTO
     * @return
     */
    @ApiOperation(value = "提交订单", notes = "提交订单")
    @PostMapping("create")
    @ChannelType(channels = "ZT")
    public Response<OrderCreateResponseApiDTO> createZhongTongOrder(@RequestBody @ParamsValid @ApiParam ZhongTongOrderCreateRequestApiDTO requestApiDTO) {
        OrderCreateResponseApiModel responseApiModel = orderBiz.createOrder2(MapperUtils.mapper(requestApiDTO, ZhongTongOrderCreateRequestApiModel.class));
        OrderCreateResponseApiDTO responseApiDTO = MapperUtils.mapper(responseApiModel, OrderCreateResponseApiDTO.class);
        return Result.SUCCESS(responseApiDTO);
    }

    @ApiOperation(value = "获取订单标签", notes = "获取订单标签")
    @PostMapping("getTag")
    public Response<OrderGetTagResponseApiDTO> getTag(@RequestBody @ParamsValid @ApiParam OrderGetTagRequestApiDTO requestApiDTO) {
        OrderGetTagResponseApiModel responseApiModel = orderBiz.getTag(MapperUtils.mapper(requestApiDTO, OrderGetTagRequestApiModel.class));
        OrderGetTagResponseApiDTO responseApiDTO = MapperUtils.mapper(responseApiModel, OrderGetTagResponseApiDTO.class);
        return Result.SUCCESS(responseApiDTO);
    }

    /**
     * 向飞鱼推送订单跟踪信息
     * @param requestApiDTO
     * @return
     */
    @ApiOperation(value = "向飞鱼推送订单跟踪信息", notes = "推送订单跟踪信息")
    @PostMapping("pushTrackingToFish")
    public Response<FishTrackResponseApiDTO>pushTrackingToFish(@RequestBody @ParamsValid @ApiParam OrderGetTrackRequestApiDTO requestApiDTO) {
        FishTrackResponseApiModel responseApiModel = orderBiz.pushFishTrackSingleBatch(requestApiDTO.getTrackingNumber());
        return Result.SUCCESS(MapperUtils.mapper(responseApiModel, FishTrackResponseApiDTO.class));
    }

    /**
     * 向飞鱼推送订单跟踪信息   测试
     * @param requestApiDTO
     * @return
     */
    @ApiOperation(value = "向飞鱼推送订单跟踪信息  测试", notes = "推送订单跟踪信息")
    @PostMapping("pushTrackingToFishTest")
    public Response<FishTrackResponseApiDTO>pushTrackingToFishTest(@RequestBody @ParamsValid @ApiParam OrderGetTrackRequestApiDTO requestApiDTO) {
        FishTrackResponseApiModel responseApiModel = orderBiz.pushFishTrack1((long) 222);
        return Result.SUCCESS(MapperUtils.mapper(responseApiModel, FishTrackResponseApiDTO.class));
    }

}
